package com.yocard.yxyd.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.yocard.yxyd.utils.util.ActivityUtils;
import com.gyf.barlibrary.ImmersionBar;
import com.yocard.yxyd.R;
import com.yocard.yxyd.base.AppContext;
import com.yocard.yxyd.http.model.response.CommonBean;
import com.yocard.yxyd.ui.activity.base.SimpleActivity;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.OnClick;

import static com.yocard.yxyd.event.EventCode.REFRESH_ORDER_LIST;

/**
 * Created on 2019/4/8.
 */
public class SettleResultActivity extends SimpleActivity {
    protected boolean isSuccess;

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_icon)
    ImageView ivIcon;
    @BindView(R.id.tv_result)
    TextView tvResult;
    @BindView(R.id.tv_tips)
    TextView tvTips;
    @BindView(R.id.btn_top)
    TextView btnTop;
    @BindView(R.id.btn_bottom)
    TextView btnBottom;
    protected String orderId;

    @Override
    protected int getLayout() {
        return R.layout.act_settle_result;
    }

    @Override
    protected void initEventAndData() {
        initTitle();
        initView();
    }

    private void initView() {
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            isSuccess = extras.getBoolean("isSuccess");
            orderId = extras.getString("id");
        }
        if(isSuccess) {
            ivIcon.setImageResource(R.mipmap.pay_successful_ico);
            tvResult.setText(R.string.pay_successed);
            tvResult.setTextColor(AppContext.getColor_(R.color.pay_success));
            tvTips.setText(R.string.order_successed_tip);
            btnTop.setText(R.string.complete_order);
            btnBottom.setText(R.string.received_again);
        } else {
            ivIcon.setImageResource(R.mipmap.pay_failure_ico);
            tvResult.setText(R.string.pay_failed);
            tvResult.setTextColor(AppContext.getColor_(R.color.primary_color));
            tvTips.setText("手速太慢，该客单已被他人抢走");
            btnTop.setText(R.string.received_again);
            btnBottom.setText(R.string.back_home);
        }
    }

    private void initTitle() {
        ImmersionBar.with(this).statusBarColor(R.color.white)
                .statusBarDarkFont(true).navigationBarColor(R.color.white).init();
        tvTitle.setText(R.string.pay);
    }

    @OnClick({R.id.iv_back,R.id.btn_top,R.id.btn_bottom})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                ActivityUtils.finishActivity(this);
                break;
            case R.id.btn_top:
                if(isSuccess){
                    Bundle bundle = new Bundle();
                    bundle.putString("id",orderId);
                    ActivityUtils.startActivity(bundle,CsmDetailActivity.class);
                    EventBus.getDefault().post(new CommonBean(4));
//                    EventBus.getDefault().post(new CommonBean(REFRESH_ORDER_LIST));
                }
                ActivityUtils.finishToActivity(MainActivity.class,false);
                break;
            case R.id.btn_bottom:
                if(!isSuccess){
                    ActivityUtils.startActivity(MainActivity.class);
                }
                ActivityUtils.finishActivity(this);
                break;
        }
    }

}
